package cuishifeng.blog.model;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang3.StringUtils;

import cuishifeng.blog.constants.BlogTitleEnum;
import lombok.Data;

/**
 * @author cuishifeng <cuishifeng0207@163.com>
 * Created on 2021-01-31
 */
@Data
public class BlogTitle {

    private String title;
    private String urlPath;
    private String mdLink;
    private String addTimeStr;
    private long addTime;
    private long updateTime;
    private String published;
    private String description;
    private String tags;
    private List<String> tagList;
    private String cover_image;
    private String canonical_url;


    public void set(String value) {
        for (BlogTitleEnum blogTitleEnum : BlogTitleEnum.values()) {
            if (StringUtils.containsIgnoreCase(value, blogTitleEnum.getName())) {
                String v = value.split(":")[1].trim();
                blogTitleEnum.getConsumer().accept(this, v);
                if (StringUtils.containsIgnoreCase(value, BlogTitleEnum.PREFIX_TAGS.getName())) {
                    if (StringUtils.isNotBlank(this.getTags())) {
                        List<String> list = Stream.of(this.getTags().split(","))
                                .map(String::trim)
                                .collect(Collectors.toList());
                        this.setTagList(list);
                    }
                }
                break;
            }
        }
    }
}
